package zclients

import (
	"context"
	"github.com/pkg/errors"
	"github.com/uber/tchannel-go/thrift"
	"go.didapinche.com/goapi/host_service_api"
	"go.didapinche.com/zeus-go/v2"
	"go.didapinche.com/zeus-go/v2/client"
	"time"
)

func NewHostService(z *zeus.Zeus) (host_service_api.TChanHostService, error) {
	c, err := client.New(z, "HostService")
	if err != nil {
		//return nil, errors.Wrap(err, "create zeus LimosService error")
		return nil, nil
	}

	tc := host_service_api.NewTChanHostServiceClient(c)

	return tc, nil
}

func FindHost2(ctx context.Context, p host_service_api.TChanHostService) (*host_service_api.HostsWithCount, error) {
	context2, _ := context.WithTimeout(ctx, 5*time.Second)
	ctx2 := thrift.Wrap(context2)
	page, err := p.FindByEnvIDAndUsageGroupAndDCAndNameOrIPLike(ctx2, 0, "", "", "", false, 0, 0)
	if err != nil {
		return nil, errors.Wrap(err, "call limosService.FindAppForPage err")
	}

	return page, nil
}
